//
// Created by ls on 23-12-31.
//
#include <iostream>
#include <map>

using namespace std;

namespace Test
{
    void printMap(const map<int, int> &M)
    {
        for (auto &[key, value] : M) {
            cout << "key = " << key << "， value = " << value << endl;
        }
    }

    void test01()
    {
        map<int, int> m;
        m.insert(pair<int, int> (1, 10));
        m.insert(pair<int, int> (2, 20));
        m.insert(pair<int, int> (3, 30));

        if (m.empty()) {
            cout << "m 为空" << endl;
        } else {
            cout << "m 不为空" << endl;
            cout << "m 的大小为：" << m.size() << endl;
        }
    }

    void test02()
    {
        map<int, int> m1;
        m1.insert(pair<int, int> (1, 10));
        m1.insert(pair<int, int> (2, 20));
        m1.insert(pair<int, int> (3, 30));

        map<int, int> m2;
        m2.insert(pair<int, int> (4, 100));
        m2.insert(pair<int, int> (5, 200));
        m2.insert(pair<int, int> (6, 300));

        cout << "交换前" << endl;
        printMap(m1);
        printMap(m2);
        cout << "-------------------------" << endl;
        m1.swap(m2);
        printMap(m1);
        printMap(m2);
    }
}

int main()
{
    // Test::test01();
    Test::test02();
}
